rich_data <- read.csv("datasets//richPK.csv")
names(rich_data) <- toupper(names(rich_data))
library(ggplot2)
library(dplyr)
##
## Attaching package: 'dplyr'
##
## The following objects are masked from 'package:stats':
##
## filter, lag
##
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(PKPDmisc)
mean_ct <- rich_data %>% group_by(TIME) %>% summarize(CONC = mean(CONC))
p_conc_time <- ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID)) +
geom_line() +
geom_point(size=2.5) +
geom_line(data = mean_ct,
aes(x = TIME, y = CONC, group=NULL),
size = 2, color = "red") +
xlab("Time (hours)") +
ylab("Concentration (mg/L)")
# regular scale
p_conc_time
# log scale
p_conc_time + scale_y_log10()
p_conc_time + facet_wrap(~RACE) + base_theme_obs()
ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID)) +
geom_line() +
geom_point()
ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID)) +
geom_line(size = 1.25) + # add size
geom_point(size = 3) # add size control
ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID)) +
geom_line(size = 1.25) +
geom_point(size = 3) +
scale_y_log10() # add scale
5) Add color by gender
ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID, color = GENDER)) +
geom_line(size = 1.25) +
geom_point(size = 3)
ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID, color = GENDER)) +
geom_line(size = 1.25) +
geom_point(size = 3) +
facet_wrap(~RACE) # use facet_wrap or facet_grid
p_conc_time <- ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID)) +
geom_line() +
geom_point(size=2.5)
# calculate mean concentration time profile
mean_ct <- rich_data %>% group_by(TIME) %>% summarize(CONC = mean(CONC))
p_conc_time +
# add new line and specify new data to draw this line
geom_line(data = mean_ct,
#don't forget group=NULL since will be looking to group by ID due to original specification in the base plot
aes(x = TIME, y = CONC, group=NULL),
size = 2, color = "red") +
# add some better label names too
xlab("Time (hours)") +
ylab("Concentration (mg/L)")
mean_ct_gender <- rich_data %>% group_by(TIME, GENDER) %>% summarize(CONC = mean(CONC))
p_conc_time +
# add new line and specify new data to draw this line
geom_line(data = mean_ct_gender,
# remember to move color into aes since you're specifying
#a column in the dataset to specify the coloring
aes(x = TIME, y = CONC, group=NULL, color = GENDER),
size = 2) +
# add some better label names too
xlab("Time (hours)") +
ylab("Concentration (mg/L)")
ggplot(data = rich_data,
aes(x = TIME, y = CONC, group=ID, color = WEIGHT)) +
geom_line(size = 1.25) +
geom_point(size = 3)
# filter to one observation per ID
ggplot(data = rich_data %>% filter(!duplicated(ID)),
aes(x = WEIGHT)) +
geom_histogram()
## stat_bin: binwidth defaulted to range/30. Use 'binwidth = x' to adjust this.
# clean up with customizations in geom_histogram
ggplot(data = rich_data %>% filter(!duplicated(ID)),
aes(x = WEIGHT)) +
geom_histogram(binwidth= 4, color="black", fill="white")
median <- rich_data %>% filter(!duplicated(ID)) %>% summarize(medianWT = median(WEIGHT))
ggplot(data = rich_data %>% filter(!duplicated(ID)),
aes(x = WEIGHT)) +
geom_histogram(binwidth= 4, color="black", fill="white") +
geom_vline(xintercept = median[["medianWT"]], size= 2, color = "red")
cmaxauc <- rich_data %>% group_by(ID, GENDER) %>% summarize(cmax = max(CONC), aucinf = AUC_inf(TIME, CONC))
ggplot(cmaxauc, aes(x = GENDER, y = cmax, group = GENDER)) + geom_boxplot()
ggplot(cmaxauc, aes(x = GENDER, y = aucinf, group = GENDER)) + geom_boxplot()
Read in EtaCov_base dataset
etacov_base <- read.csv("datasets/EtaCov_base.csv")
library(GGally)
## Warning: package 'GGally' was built under R version 3.1.1
ggpairs(etacov_base %>% select(nV, nCl, nKa),
lower=list(continuous="smooth", params=c(colour="black")),
diag=list(continuous="density", params=c(colour="black", fill = "white")), axisLabels = "show")
etacov_base$Scenario <- NULL
library(reshape2)
enc_melt <- melt(etacov_base, id.vars=c("ID", "WT"))
gg_covwt <- ggplot(enc_melt, aes(x = WT, y=value, group = ID))
gg_covwt+ geom_point() +
facet_wrap(~variable)
gg_covwt+ geom_point() +
facet_wrap(~variable)+ stat_smooth(aes(group= variable), se=F, size = 1.25)
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.
## geom_smooth: method="auto" and size of largest group is <1000, so using loess. Use 'method = x' to change the smoothing method.